<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Laborline_Create extends Page
{
       public $chkPaid = null;
       public $hfForm = null;
       public $edRef = null;
       public $Label2 = null;
       public $JSRoundDecimal = null;
       public $JSAJAX = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $btnShowDescription = null;
       public $JTDivDescription = null;
       public $JTGroupBox4 = null;
       public $btnAddDescription = null;
       public $btnDelDescription = null;
       public $edDescription = null;
       public $listDescription = null;
       public $JTDate = null;
       public $Label1 = null;
       public $hiddenVeh = null;
       public $Image1 = null;
       public $hiddenWO = null;
       public $cmbperformed = null;
       public $edLaborUnits = null;
       public $hiddenLine = null;
       public $JTSiteTheme1 = null;
       public $memoNotes = null;
       public $lblNotes = null;
       public $cmbDescription = null;
       public $lblDescription = null;
       public $chkWarranty = null;
       public $edTotal = null;
       public $lblTotal = null;
       public $edCost = null;
       public $lblCost = null;
       public $lblLaborUnits = null;
       public $cmbName = null;
       public $lblPerformed = null;
       function Vehicle_Laborline_CreateJSLoad($sender, $params)
       {

       ?>


       <?php

       }

       function btnCancelJSClick($sender, $params)
       {

       ?>
       window.close();
       <?php

       }


       function btnDelDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var DescIndex = document.getElementById('listDescription').selectedIndex;
       var DescValue = document.getElementById('listDescription')[DescIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxDesc3(DescValue,comp);
       <?php

       }

       function btnAddDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var adddesc = document.getElementById('edDescription').value;
       var compider = document.getElementById('compid').value;
       AjaxDesc2(adddesc,compider);
       document.Vehicle_Laborline_Create.edDescription.value = "";
       <?php

       }

       function btnShowDescriptionJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivDescription').Show();
       document.Vehicle_Laborline_Create.edDescription.value = "";
       <?php

       }

       function cmbperformedChange($sender, $params)
       {
       $performed = $this->cmbperformed->getItemIndex();
       if($performed=='employee')
       {
       $this->cmbName->Clear();
       $result_emp = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."'");

       while($row_emp = mysql_fetch_array($result_emp))
       {
            $this->cmbName->AddItem($row_emp['lname'].','.$row_emp['fname'], null, $row_emp['lname'].','.$row_emp['fname']);
       }
       }

       if($performed=='vendor')
       {
       $this->cmbName->Clear();
       $result_vendor = mysql_query("select * from vendor_tbl where company_id='".$_SESSION['company_id']."'");

       while($row_vendor = mysql_fetch_array($result_vendor))
       {
            $this->cmbName->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
       }
       }

       if($performed=='--Select--')
       {
       $this->cmbName->Clear();
       }

       }

       function btnCancelClick($sender, $params)
       {
       redirect('veh_laborline_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue());


       }

       function btnSubmitClick($sender, $params)
       {

       if($this->chkWarranty->Checked==true)
       {
       $warranty='1';
       }
       else
       {
       $warranty='0';
       }

       mysql_query("INSERT INTO veh_laborline_tbl(company_id,
       vehicle_id,
       workorder,
       performed_by,
       employee,
       reference_num,
       labor_date,
       labor_unit,
       cost,
       total,
       description,
       notes,
       warranty)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$this->hiddenVeh->getValue()."',
       '".$this->hiddenWO->getValue()."',
       '".$this->cmbperformed->getItemIndex()."',
       '".$this->cmbName->getItemIndex()."',
       '".$this->edRef->Text."',
       '".$this->JTDate->Text."',
       '".$this->edLaborUnits->Text."',
       '".$this->edCost->Text."',
       '".$this->edTotal->Text."',
       '".$this->cmbDescription->getItemIndex()."',
       '".$this->memoNotes->Text."',
       '".$warranty."')") or die("INSERT LABORLINE - ".mysql_error());

       //redirect('veh_laborline_list.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue());
       /*echo '<script language=javascript>
       window.opener.setWODetails();
       window.opener.JTFrameLabor.location.reload();
       window.location.href="veh_laborline_create.php?veh='.$this->hiddenVeh->getValue().'&WO='.$this->hiddenWO->getValue().'";
       alert("Successfully Added Record!");
       window.close();
       </script>';*/

       echo "<script type='text/javascript'>
       alert('Successfully added record!');
       window.opener.setWODetails();
       window.opener.JTFrameLabor.location.reload();
       var answer = confirm('Add another record?');
       if(answer)
       {
       window.location.href='veh_laborline_create.php?veh=".$this->hiddenVeh->getValue()."&WO=".$this->hiddenWO->getValue()."';
       }
       else
       {
       window.close();
       }
       </script>";
       }




       function edCostJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Laborline_Create.edTotal.value = roundNumber((document.Vehicle_Laborline_Create.edLaborUnits.value) * (document.Vehicle_Laborline_Create.edCost.value),2);

       //accept only numbers
       var numero = document.getElementById("edCost").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edCost").value = numero;


       <?php

       }

       function edLaborUnitsJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.Vehicle_Laborline_Create.edTotal.value = roundNumber((document.Vehicle_Laborline_Create.edLaborUnits.value) * (document.Vehicle_Laborline_Create.edCost.value),2);
       <?php

       }

       function clr()
       {
       $this->JTDate->setText(date('Y-m-d'));
       $this->edLaborUnits->Text="1";
       $this->edCost->Text="";
       $this->edTotal->Text="";
       $this->memoNotes->Text="&nbsp";
       $this->chkWarranty->Checked=false;
       $this->cmbperformed->setItemIndex('--Select--');
       }




       function Vehicle_Laborline_CreateCreate($sender, $params)
       {
       $this->clr();

       $this->compid->Value = $_SESSION['company_id'];
       $veh_id = $_GET['veh'];
       $WO = $_GET['WO'];
       $form = $_GET['form'];
       if($veh_id!=null || $veh_id!='')
       $this->hiddenVeh->setValue($veh_id);
       $this->hiddenWO->setValue($WO);
       $this->hfForm->setValue($form);

       $this->JTDate->setText(date('Y-m-d'));
       $this->edLaborUnits->Text="1";
       $this->edCost->Text="";
       $this->edTotal->Text="";
       $this->edRef->Text="";
       $this->memoNotes->Text="&nbsp";
       $this->chkWarranty->Checked=false;
       $this->cmbName->Clear();

       $this->cmbDescription->Clear();
        $result_desc = mysql_query("select value from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."'and category='task descriptions'");

        while($row_desc = mysql_fetch_array($result_desc))
        {
            $this->cmbDescription->AddItem($row_desc['value'], null, $row_desc['value']);
        }

        //list description
        $result_d = mysql_query("select value from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."'and category='task descriptions'");

        while($row_d = mysql_fetch_array($result_d))
        {
            $this->listDescription->AddItem($row_d['value'], null, $row_d['value']);
        }

       }


}

global $application;

global $Vehicle_Laborline_Create;

//Creates the form
$Vehicle_Laborline_Create=new Vehicle_Laborline_Create($application);

//Read from resource file
$Vehicle_Laborline_Create->loadResource(__FILE__);

//Shows the form
$Vehicle_Laborline_Create->show();

?>